﻿@model Nop.Admin.Models.Logistics.LogisticsModel
@using Telerik.Web.Mvc.UI
@{
    //page title
    ViewBag.Title = T("Admin.Logistics.Overview").Text;
}

<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/subsites/Administration/Content/images/ico-system.png")" alt="" />
        @T("Admin.Logistics.Overview").Text
    </div>
</div>
<table class="stats">
    <tbody>
        <tr>
            <td class="orderaveragereport">
                <div class="statisticsTitle">
                    @T("Admin.Logistics.PendingPackage").Text
                </div>
                @Html.Action("PendingPackages")
            </td>
        </tr>
    </tbody>
</table>
<table class="stats">
    <tbody>
        <tr>
            <td class="orderstatistics">
                <div class="statisticsTitle">
                    @T("Admin.Logistics.AvailableCourier").Text
                </div>
                @Html.Action("AvailableCouriers")
            </td>
        </tr>
    </tbody>
</table>

@if (@Model.MapContext != null)
{
    <div>
        <script type="text/javascript">
            $(document).ready(function () {
                @if (Model.Packages.Count() > 0)
                {
                <Text>getMap();</Text>
                }
            });
        </script>
        <table class="stats">
            <tbody>
                <tr>
                    <td class="orderstatistics">
                        @Html.Partial("ShowMap", Model.MapContext)
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
}

<script type="text/javascript">

    var selectedIds = [];

    function onDataBound(e) {

        $('#available-drivers input[type=checkbox][id!=mastercheckbox]').each(function () {
            var currentId = $(this).val();
            var checked = jQuery.inArray(currentId, selectedIds);
            //set checked based on if current checkbox's value is in selectedIds.  
            $(this).attr('checked', checked > -1);
        });

        updateMasterCheckbox();
    }

    function updateMasterCheckbox() {
        var numChkBoxes = $('#available-drivers input[type=checkbox][id!=mastercheckbox]').length;
        var numChkBoxesChecked = $('#available-drivers input[type=checkbox][checked][id!=mastercheckbox]').length;
        $('#mastercheckbox').attr('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
    }

</script>
